Skip to content

[PATCH] clk: mediatek: fix memory leak on module removal#57

Draft
akku1139 wants to merge 8 commits into
mainlinefrom
patch/mtk-apmixed-memoryleak
Draft

[PATCH] clk: mediatek: fix memory leak on module removal#57
akku1139 wants to merge 8 commits into
mainlinefrom
patch/mtk-apmixed-memoryleak

Conversation

@akku1139

Copy link
Copy Markdown
Member

Some MediaTek clock drivers do not call platform_set_drvdata() during probe(), but their remove() callback calls platform_get_drvdata(). This results in platform_get_drvdata() returning NULL, which leads to calling mtk_free_clk_data(NULL) -> kfree(NULL).
Therefore, the actual clk_data is never released, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 124294f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")
Fixes: 4c02c9a ("clk: mediatek: mt8173: Break down clock drivers and allow module build")
Fixes: 54b7026 ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")
Fixes: c50e2ea ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")
Fixes: 0d36328 ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")
Fixes: c6368ce ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")
Fixes: 838b863 ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")

Some MediaTek clock drivers do not call platform_set_drvdata() during
probe(), but their remove() callback calls platform_get_drvdata(). This
results in platform_get_drvdata() returning NULL, which leads to calling
mtk_free_clk_data(NULL) -> kfree(NULL).
Therefore, the actual clk_data is never released, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 124294f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")
Fixes: 4c02c9a ("clk: mediatek: mt8173: Break down clock drivers and allow module build")
Fixes: 54b7026 ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")
Fixes: c50e2ea ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")
Fixes: 0d36328 ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")
Fixes: c6368ce ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")
Fixes: 838b863 ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
@akku1139

akku1139 commented Jun 29, 2026

Copy link
Copy Markdown
Member Author

@akku1139 akku1139 added the Bug label Jun 29, 2026
@akku1139 akku1139 changed the title clk: mediatek: fix memory leak on module removal [PATCH] clk: mediatek: fix memory leak on module removal Jun 29, 2026
Revert "clk: mediatek: fix memory leak on module removal"

This reverts commit 1cc6568.
@akku1139

akku1139 commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

for v2

  • clk-mt2712-apmixedsys.c
  • clk-mt6795-apmixedsys.c
  • clk-mt6795-infracfg.c
  • clk-mt6795-pericfg.c
  • clk-mt7622-apmixedsys.c
  • clk-mt7622-infracfg.c
  • clk-mt8135-apmixedsys.c
  • clk-mt8173-apmixedsys.c
  • clk-mt8173-infracfg.c
  • clk-mt8192-apmixedsys.c

@akku1139

akku1139 commented Jul 7, 2026

Copy link
Copy Markdown
Member Author
Fixes: 124294ff468f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")

akku1139 added 6 commits July 7, 2026 16:09
clk_mt2712_apmixed_probe() in clk-mt2712-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt2712_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to
calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: c6368ce ("clk: mediatek: mt2712-apmixedsys: Add .remove() callback for module build")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
clk-mt6795-apmixedsys.c, clk-mt6795-infracfg.c and clk-mt6795-pericfg.c
do not call platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL, which leads to
calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 0d36328 ("clk: mediatek: Add MediaTek Helio X10 MT6795 clock drivers")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
clk-mt7622-apmixedsys.c and clk-mt7622-infracfg.c do not call
platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: c50e2ea ("clk: mediatek: mt7622-apmixedsys: Add .remove() callback for module build")
Fixes: 838b863 ("clk: mediatek: mt7622: Move infracfg to clk-mt7622-infracfg.c")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
clk_mt8135_apmixed_probe() in clk-mt8135-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt8135_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 54b7026 ("clk: mediatek: mt8135-apmixedsys: Convert to platform_driver and module")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
clk-mt8173-apmixedsys.c and clk-mt8173-infracfg.c do not call
platform_set_drvdata() during their driver probe callback,
but their remove callback calls platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 4c02c9a ("clk: mediatek: mt8173: Break down clock drivers and allow module build")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
clk_mt8192_apmixed_probe() in clk-mt8192-apmixedsys.c does not call
platform_set_drvdata(), but clk_mt8192_apmixed_remove() callback calls
platform_get_drvdata().
This results in platform_get_drvdata() returning NULL,
which leads to calling kfree(NULL) in mtk_free_clk_data(NULL).
This leaves clk_data unreleased, causing a memory leak.

Fix this by calling platform_set_drvdata() during probe.

Fixes: 124294f ("clk: mediatek: mt8192: Move apmixedsys clock driver to its own file")
Cc: stable@vger.kernel.org
Signed-off-by: Akari Tsuyukusa <akkun11.open@gmail.com>
@akku1139

akku1139 commented Jul 7, 2026

Copy link
Copy Markdown
Member Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant